package com.beep.erp.model.stockdetail;

import com.beep.erp.common.base.BaseBean;
import com.beep.erp.common.bean.BizStorageLocationsListBean;
import com.beep.erp.common.bean.StockListBean;
import com.beep.erp.http.HttpExceptionHandle;
import com.beep.erp.http.HttpResultSubscriber;
import com.beep.erp.model.addinstock.SaveStockBody;

import rx.schedulers.Schedulers;

/**
 * Created by Jolly on 2018/9/2.
 */

public class StockDetailPresenter extends StockDetailContract.Presenter {
    @Override
    public void getStockDetail(String sign, String timeStamp, String purchaseId) {
        mRxManage.add(mModel.getStockDetail(sign, timeStamp, purchaseId).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<StockListBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(StockListBean stockListBean) {
                mView.hideLoading();
                mView.getStockDetail(stockListBean);
            }
        }));
    }

    @Override
    public void saveInstock(String sign, String timeStamp, SaveStockBody saveStockBody) {
        mView.showLoading();
        mRxManage.add(mModel.saveInstock(sign, timeStamp, saveStockBody).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<BaseBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(BaseBean baseBean) {
                mView.hideLoading();
                mView.saveInstock();
            }
        }));
    }

    @Override
    public void getBizStorageLocationList(String sign, String timeStamp, String type) {
        mRxManage.add(mModel.getBizStorageLocationList(sign, timeStamp, type).unsubscribeOn(Schedulers.io()).subscribe(new HttpResultSubscriber<BizStorageLocationsListBean>() {
            @Override
            public void onError(HttpExceptionHandle.ResponeThrowable e) {
                mView.hideLoading();
                mView.showMessage(e.ErrorInfo);
            }

            @Override
            public void onNext(BizStorageLocationsListBean bizStorageLocationsListBean) {
                mView.hideLoading();
                mView.getBizStorageLocationList(bizStorageLocationsListBean);
            }
        }));
    }

    @Override
    public void onStart() {
        mView.getDate();
    }

}
